'use strict'

let Arena = require('./model').Arena
let serverConfig = require('../../config/serverConfig').serverConfig
let serverId = serverConfig.serverId

Arena.find({
  _id: serverId
}, function(err, res) {
  if (!err) {
    if (!res || res.length === 0) {
      let arena = new Arena({
        _id: serverId,
        players: [],
        playersArray: [],
      })
      arena.save()
    }
  }
})


/**
 * 根据查询条件, 查找
 */
exports.getArena = function(callback) {
  Arena.findOne({
    _id: serverId
  }, function(err, res) {
    if (err || !res || res.length === 0) {
      callback(null)
    }else{
      callback(res)
    }

  })
}

/**
 * 根据查询条件, 更新
 */
exports.saveArena = function(field, callback) {
  Arena.update({
    _id: serverId
  }, field, {}, callback)
}
